home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / ax25.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-24  |  9.8 KB  |  290 lines

  1. #ifndef    _AX25_H
  2. #define    _AX25_H
  3.  
  4. #ifndef    _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.  
  8. #ifndef    _MBUF_H
  9. #include "mbuf.h"
  10. #endif
  11.  
  12. #ifndef _TIMER_H
  13. #include "timer.h"
  14. #endif
  15.  
  16. #ifndef    _IFACE_H
  17. #include "iface.h"
  18. #endif
  19.  
  20. #ifndef _SOCKET_H
  21. #include "socket.h"
  22. #endif
  23.  
  24. /* AX.25 datagram (address) sub-layer definitions */
  25.  
  26. #define AXROUTESIZE     499
  27. #define AXROUTEHOLDTIME    (60L*60*24*30)
  28.  
  29. extern int32 Axholdtime;
  30. extern int Attended;
  31.  
  32. #define    MAXDIGIS    7    /* Maximum number of digipeaters */
  33. #define    ALEN        6    /* Number of chars in callsign field */
  34. #define    AXALEN        7    /* Total AX.25 address length, including SSID */
  35. #define    AXBUF        10    /* Buffer size for maximum-length ascii call */
  36.  
  37. /* Bits within SSID field of AX.25 address */
  38. #define    SSID        0x1e    /* Sub station ID */
  39. #define    REPEATED    0x80    /* Has-been-repeated bit in repeater field */
  40. #define    E        0x01    /* Address extension bit */
  41. #define    C        0x80    /* Command/response designation */
  42.  
  43. /* Upper sub-layer (LAPB) definitions */
  44. /* Control field templates */
  45. #define    I        0x00        /* Information frames */
  46. #define    S        0x01        /* Supervisory frames */
  47. #define    RR        0x01        /* Receiver ready */
  48. #define    RNR        0x05        /* Receiver not ready */
  49. #define    REJ        0x09        /* Reject */
  50. #define    U        0x03        /* Unnumbered frames */
  51. #define    SABM        0x2f        /* Set Asynchronous Balanced Mode */
  52. #define    DISC        0x43        /* Disconnect */
  53. #define    DM        0x0f        /* Disconnected mode */
  54. #define    UA        0x63        /* Unnumbered acknowledge */
  55. #define    FRMR        0x87        /* Frame reject */
  56. #define    UI        0x03        /* Unnumbered information */
  57. #define    PF        0x10        /* Poll/final bit */
  58. #define DAMA        0x20        /* DAMA master id */
  59.  
  60. #define    MMASK    7            /* Mask for modulo-8 sequence numbers */
  61.  
  62. /* FRMR reason bits */
  63. #define    W        1        /* Invalid control field */
  64. #define    X        2        /* Unallowed I-field */
  65. #define    Y        4        /* Too-long I-field */
  66. #define    Z        8        /* Invalid sequence number */
  67.  
  68. /* AX25 protocol constants */
  69. #define DST_C   1        /* Set C bit in dest addr */
  70. #define SRC_C   2        /* Set C bit in source addr */
  71. #define VERS1   0        /* AX25L2V1 compatible frame */
  72. #define CMD     (DST_C)        /* Command frame */
  73. #define POLL    (DST_C|PF)    /* Poll frame */
  74. #define RESP    (SRC_C)        /* Response frame */
  75. #define FINAL   (SRC_C|PF)    /* Final frame */
  76.  
  77. /* Round trip timing parameters */
  78. #define AGAIN   8               /* Average RTT gain = 1/8 */
  79. #define DGAIN   4               /* Mean deviation gain = 1/4 */
  80.  
  81. extern struct iface *axroute_default_ifp;
  82.  
  83. extern char Mycall[AXALEN], Ax25multi[][AXALEN], *Ax25states[],
  84.             *Ax25reasons[], Nomycall[];
  85.  
  86. extern int T3disc;
  87.  
  88. extern int16 Digipeat,T1init,T2init,T3init,T4init,T5init,T6init,Retries,
  89.              Maxframe,Paclen,Pthresh,Axwindow;
  90.  
  91. /* Internal representation of an AX.25 address */
  92. struct ax25_addr {
  93.     char call[ALEN];
  94.     char ssid;
  95. };
  96. #define NULLAXADDR (struct ax25_addr *)0
  97.  
  98. struct axroute_tab {
  99.     struct ax25_addr call;
  100.     struct axroute_tab *digi;
  101.     struct iface *ifp;
  102.     int perm;
  103.     long time;
  104.     struct axroute_tab *next;
  105. };
  106.  
  107. extern struct axroute_tab *axroute_tab[];
  108.  
  109. struct ax_saverecord {
  110.     struct ax25_addr call,digi;
  111.     short dev;
  112.     long time;
  113. };
  114.  
  115. /* Internal representation of an AX.25 header */
  116. struct ax25 {
  117.     struct ax25_addr dest;            /* Destination address */
  118.     struct ax25_addr source;        /* Source address */
  119.     struct ax25_addr digis[MAXDIGIS];    /* Digi string */
  120.     int ndigis;                /* Number of digipeaters */
  121.     int cmdrsp;                /* Command/response */
  122. };
  123.  
  124. /* Per-connection link control block
  125.  * These are created and destroyed dynamically,
  126.  * and are indexed through a hash table.
  127.  * One exists for each logical AX.25 Level 2 connection
  128.  */
  129. struct ax25_cb {
  130.     struct ax25_cb *next;        /* linked list pointers */
  131.  
  132.     char path[70];
  133.     int pathlen;
  134.  
  135.     struct iface *iface;        /* Interface */
  136.  
  137.     struct mbuf *txq;        /* Transmit queue */
  138.     struct mbuf *rxasm;        /* Receive reassembly buffer */
  139.     struct mbuf *rxq;        /* Receive queue */
  140.     int16 rcvcnt;
  141.     int32 sndqtime;
  142.  
  143.     struct axreseq {        /* Resequencing queue */
  144.         struct mbuf *bp;
  145.         int sum;
  146.     } reseq[8];
  147.  
  148.     char rejsent;            /* REJ frame has been sent */
  149.     char rnrsent;               /* RNR frame has been sent */
  150.     char polling;            /* Poll frame has been sent */
  151.     char clone;            /* Server-type cb, will be cloned */
  152.     int32 remotebusy;        /* Remote sent RNR */
  153.  
  154.     char reason;            /* Reason for connection closing */
  155. #define    LB_NORMAL        0    /* Normal close */
  156. #define    LB_DM            1    /* Received DM from other end */
  157. #define    LB_TIMEOUT        2    /* Excessive retries */
  158. #define LB_UNUSED        3    /* Link is redundant - unused */
  159.     int mode;
  160. #define STREAM            0
  161. #define DGRAM            1
  162.     char vs;            /* Our send state variable */
  163.     char vr;            /* Our receive state variable */
  164.     char unack;            /* Number of unacked frames */
  165.     int closed;            /* disc when sendqueue empty */
  166.     int cwind;            /* Congestion window */
  167.     unsigned retries;        /* Retry counter */
  168.     int state;            /* Link state */
  169. #define    DISCONNECTED        1
  170. #define LISTEN            2
  171. #define    CONNECTING        3
  172. #define    DISCONNECTING        4
  173. #define    CONNECTED        5
  174.     struct timer t1;        /* Retransmission timer */
  175.     struct timer t2;        /* Acknowledgement delay timer */
  176.     struct timer t3;        /* Keep-alive poll timer */
  177.     struct timer t4;        /* Link redundancy timer */
  178.     struct timer t5;        /* Packet assembly timer */
  179.     struct timer t6;        /* DAMA timeout timer */
  180.     int32 srt;            /* Smoothed round-trip time, ms */
  181.     int32 mdev;            /* Mean rtt deviation, ms */
  182.     int32 sndtime[8];        /* time of 1st transmission */
  183.  
  184.     void (*r_upcall) __ARGS((struct ax25_cb *,int));    /* Receiver upcall */
  185.     void (*t_upcall) __ARGS((struct ax25_cb *,int));    /* Transmit upcall */
  186.     void (*s_upcall) __ARGS((struct ax25_cb *,int,int));    /* State change upcall */
  187.  
  188.     int user;            /* User pointer */
  189.     int segremain;            /* Segmenter state */
  190.     struct mbuf *segasm;        /* Segmenter reassembly buffer */
  191.     struct ax25_cb *peer;       /* Pointer to peer's control block */
  192.     char dama;            /* DAMA flag */
  193.     char flushed;            /* flush all sub channels at one DAMA poll */
  194. };
  195. #define    NULLAX25    ((struct ax25_cb *)0)
  196.  
  197. extern struct ax25_cb Ax25default,*Ax25_cb;
  198.  
  199. /* C-bit stuff */
  200. #define    LAPB_UNKNOWN    0
  201. #define    LAPB_COMMAND    1
  202. #define    LAPB_RESPONSE    2
  203.  
  204. /* AX.25 Level 3 Protocol IDs (PIDs) */
  205. #define PID_X25            0x01    /* CCITT X.25 PLP */
  206. #define    PID_SEGMENT        0x08    /* Segmentation fragment */
  207. #define PID_TEXNET        0xc3    /* TEXNET datagram protocol */
  208. #define    PID_LQ            0xc4    /* Link quality protocol */
  209. #define    PID_APPLETALK        0xca    /* Appletalk */
  210. #define    PID_APPLEARP        0xcb    /* Appletalk ARP */
  211. #define    PID_IP            0xcc    /* ARPA Internet Protocol */
  212. #define    PID_ARP            0xcd    /* ARPA Address Resolution Protocol */
  213. #define PID_FLEXNET        0xce    /* Flexnet routing info */
  214. #define    PID_NETROM        0xcf    /* NET/ROM */
  215. #define    PID_NO_L3        0xf0    /* No level 3 protocol */
  216.  
  217. #define    SEG_FIRST        0x80    /* First segment of a sequence */
  218. #define    SEG_REM            0x7f    /* Mask for # segments remaining */
  219.  
  220. #define    AX_EOL            "\r"    /* AX.25 end-of-line convention */
  221.  
  222. /* Link quality database record format
  223.  * Currently used only by AX.25 interfaces
  224.  */
  225. struct lq {
  226.     char addr[AXALEN];        /* Hardware address of station heard */
  227.     int32 time;            /* Time station was last heard */
  228.     int32 currxcnt;            /* Current # of packets heard from this station */
  229.     unsigned char pid;
  230.     unsigned char lock;
  231. };
  232. #define    NULLLQ    (struct lq *)0
  233.  
  234. /* Max number of fake AX.25 interfaces for RFC-1226 encapsulation */
  235. #define NAX25   10
  236.  
  237. /* Codes for the open_ax25 call */
  238. #define    AX_PASSIVE    0
  239. #define    AX_ACTIVE    1
  240. #define    AX_SERVER    2    /* Passive, clone on opening */
  241.  
  242. void ax_recv __ARGS((struct iface *,struct mbuf *));
  243. void axip_input __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,int rxbroadcast));
  244. int axip_raw __ARGS((struct iface *iface,struct mbuf *bp));
  245. int ax_send __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,int prec,
  246.             int del,int tput,int rel));
  247. int ax_output __ARGS((struct iface *iface,char *dest,char *source,int16 pid,
  248.               struct mbuf *data));
  249. struct axroute_tab *axroute_tabptr __ARGS((struct ax25_addr *call,int create));
  250. void axroute_add __ARGS((struct ax25_cb *cp,int perm));
  251. int is_bud __ARGS((char *call,int store));
  252. void logaddr __ARGS((struct iface *iface,char *addr,char pid));
  253. void axflush __ARGS((struct iface *ifp));
  254. int maxheard __ARGS((struct iface *ifp,int num));
  255. int ax25val __ARGS((struct ax25_cb *axp));
  256. int disc_ax25 __ARGS((struct ax25_cb *axp));
  257. int kick_ax25 __ARGS((struct ax25_cb *axp));
  258. struct ax25_cb *open_ax25 __ARGS((struct iface *,char *,char *,int,
  259.     void (*) __ARGS((struct ax25_cb *,int)),
  260.     void (*) __ARGS((struct ax25_cb *,int)),
  261.     void (*) __ARGS((struct ax25_cb *,int,int)),int user));
  262. struct mbuf *recv_ax25 __ARGS((struct ax25_cb *axp,int16 cnt));
  263. int reset_ax25 __ARGS((struct ax25_cb *axp));
  264. int send_ax25 __ARGS((struct ax25_cb *axp,struct mbuf *bp,int pid));
  265. int addreq __ARGS((char *a,char *b));
  266. void addrcp __ARGS((char *to,char *from));
  267. struct ax25_cb *find_ax25 __ARGS((char *,char *));
  268. void del_ax25 __ARGS((struct ax25_cb *axp));
  269. char *pax25 __ARGS((char *e,char *addr));
  270. int setcall __ARGS((char *out,char *call));
  271. int  sendctl __ARGS((struct ax25_cb *axp,int cmdrsp,int cmd));
  272. void t1_timeout __ARGS((struct ax25_cb *cp));
  273. void t2_timeout __ARGS((struct ax25_cb *cp));
  274. void t3_timeout __ARGS((struct ax25_cb *cp));
  275. void t4_timeout __ARGS((struct ax25_cb *cp));
  276. void t5_timeout __ARGS((struct ax25_cb *cp));
  277. void t6_timeout __ARGS((struct ax25_cb *cp));
  278. struct mbuf *segmenter __ARGS((struct mbuf *bp,int16 ssize));
  279. void init_maxheard __ARGS((struct iface *ifp));
  280. void doroutelistentry __ARGS((struct axroute_tab *rp));
  281. void build_path __ARGS((struct ax25_cb *axp,struct iface *ifp,char *newpath,int reverse, int newsrt));
  282. void st_ax25 __ARGS((struct ax25_cb *cp));
  283.  
  284. /* In socket.c: */
  285. void s_arcall __ARGS((struct ax25_cb *axp,int cnt));
  286. void s_ascall __ARGS((struct ax25_cb *axp,int old,int new));
  287. void s_atcall __ARGS((struct ax25_cb *axp,int cnt));
  288.  
  289. #endif    /* _AX25_H */
  290.